<!--
 * Description: CBOM数据修改
 * Company: 联宝（合肥）电子科技有限公司
 * Author: Qiuxue.Wu
 * Date: 2020/09/15 16:14
-->

<template>
  <div v-loading="isRequesting">
    <!--数据表单-->
    <el-form label-width="150px" :model="formData" size="mini">
      <el-row>
        <!--BU类型-->
        <el-col :span="12">
          <el-form-item :label="$t('Cbom.bu')">
            <el-select v-model="formData.bu" clearable :placeholder="$t('select.placeholder')">
              <el-option
                v-for="item in $store.getters['enums/getBuList']"
                :key="item"
                :label="item"
                :value="item"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <!--产品专案-->
        <el-col :span="12">
          <el-form-item :label="$t('Cbom.project')">
            <el-select
              v-model="formData.project"
              clearable
              disabled
              filterable
              :placeholder="$t('select.placeholder')"
            >
              <el-option
                v-for="item in projectList"
                :key="item.projectId"
                :label="item.projectName"
                :value="item.projectName"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <!--Tracking Sku-->
        <el-col :span="12">
          <el-form-item :label="$t('Cbom.trackingSku')">
            <el-input
              v-model="formData.trackingSku"
              v-blur:trackingSku="formData"
              clearable
              disabled
              :placeholder="$t('input.placeholder')"
            />
          </el-form-item>
        </el-col>
        <!--CBOM版本-->
        <el-col :span="12">
          <el-form-item :label="$t('Cbom.cbomVersion')">
            <el-input
              v-model="formData.cbomVersion"
              v-blur:cbomVersion="formData"
              clearable
              disabled
              :placeholder="$t('input.placeholder')"
            />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <span style="display: block;text-align: center;margin-top: 5px">
      <!--取消按钮-->
      <el-button size="medium" @click="cancel">{{ $t('button.cancel') }}</el-button>
      <!--保存按钮-->
      <el-button size="medium" type="primary" @click="save">{{ $t('button.save') }}</el-button>
    </span>
  </div>
</template>

<script>
import { cbomInfoEdit } from '@/api/cbom/info'

export default {
  name: 'CbomEdit',
  props: {
    /** 修改的行数据 */
    rowData: {
      type: Object,
      default: () => {}
    },
    /** 专案数据列表 */
    projectList: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      /** 表单数据 */
      formData: {},
      /** 正在查询 */
      isRequesting: false
    }
  },
  created() {
    this.formData = this.$deepCopy(this.rowData)
  },
  methods: {
    async save() {
      try {
        await this.$confirmBox(this.$t('button.save'), 'success')
        this.isRequesting = true
        await cbomInfoEdit(this.formData, { msgSuccess: true, msgError: true })
        this.$bus.$emit('cbom-reload')
        this.cancel()
      } catch (error) {
        console.log(error)
      } finally {
        this.isRequesting = false
      }
    },
    cancel() {
      this.$emit('cancel')
    }
  }
}
</script>
